package avl.recursion;

public class Node {
    private Node left, right;
    /**
     * 通过判断左右子节点的高度差，判断是否为不平衡点 <br>
     */
    private int height;
    private int val;

    /**
     * 从外部逐步插入节点，或删除 后数据变化，不考虑 子节点作为参数的初始化
     */
    public Node(int val) {
        this.height = 1;
        this.val = val;
    }

    public void computerHeight() {
        int leftHeight = left == null ? 0 : left.height;
        int rightHeight = right == null ? 0 : right.height;;
        this.height = Math.max(leftHeight, rightHeight) + 1;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public void setLeftAndComputerHeight(Node left) {
        this.left = left;
        this.computerHeight();
    }

    public Node getLeft() {
        return left;
    }

    public Node getRight() {
        return right;
    }

    public void setRight(Node right) {
        this.right = right;
        computerHeight();
    }

    public void setRightAndComputerHeight(Node right) {
        this.right = right;
        this.computerHeight();
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public int getHeight() {
        return height;
    }

}
